const Controller = require('../../core/controller/ApiController');
const {Route, HttpGet, HttpPut, HttpPost, Middleware, filters} = require('../../../plugin/egg-decorator-router/lib');
const {ExceptionHandler} = require('../../../plugin/egg-controller-exception-handler/lib');


@Route('/api/mobile/staff')
class StaffController extends Controller {

    //登录
    @HttpPost('/login')
    @ExceptionHandler()
    async login() {
        const rule = {
            phone: 'string',
            pwd: 'string',
            remember: 'int'
        };
        const body = this.ctx.request.body;
        this.validate(rule, body);
        this.result.data = await this.service.mobile.staff.main.login(body.phone, body.pwd, body.remember);
        return '登录成功' //返回prompt，可选，一般不需要
    }

    //退出
    @HttpPost('/logout')
    @ExceptionHandler()
    async logout() {
        await this.service.mobile.staff.main.logout();
        return '退出登录' //返回prompt，可选，一般不需要
    }

    //获取个人信息
    @HttpGet('/info')
    @ExceptionHandler()
    async getStaffInfo() {
        this.result.data = await this.service.mobile.staff.main.getStaffInfo();
        return '查询成功'
    }

    //修改密码
    @HttpPost('/change/pwd')
    @ExceptionHandler()
    async updateStaffPwd() {
        const rule = {
            old_pwd: 'string',
            new_pwd: 'string'
        };
        const body = this.ctx.request.body;
        this.validate(rule, body);
        await this.service.mobile.staff.main.updateStaffPwd(body.old_pwd, body.new_pwd);
        return '修改成功'
    }


}

module.exports = StaffController;

